package com.fjh.springboot_01.mapper;

import com.fjh.springboot_01.pojo.lesson.LessonLike;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LessonLikeMapper {
    // 添加点赞记录
    @Insert("INSERT INTO lesson_like(lesson_id, user_id, create_time) VALUES(#{lessonId}, #{userId}, #{createTime})")
    void add(LessonLike lessonLike);

    // 删除点赞记录
    @Delete("DELETE FROM lesson_like WHERE lesson_id = #{lessonId} AND user_id = #{userId}")
    void delete(@Param("lessonId") Integer lessonId, @Param("userId") Integer userId);

    // 查询用户是否点赞了某课程
    @Select("SELECT COUNT(*) FROM lesson_like WHERE lesson_id = #{lessonId} AND user_id = #{userId}")
    Integer exists(@Param("lessonId") Integer lessonId, @Param("userId") Integer userId);

    // 查询课程点赞数量
    @Select("SELECT COUNT(*) FROM lesson_like WHERE lesson_id = #{lessonId}")
    Integer count(@Param("lessonId") Integer lessonId);
} 